import type { ExtIdTuple, ExtUUidTuple, INTEGER_PG, VARCHAR255_PG } from "~/db.pg";

import { ExtOwner } from "@/stream-user/core.define";

import { ENUM_PAYMENT, ENUM_PAYMENT_WECHAT_MP_STATE, ENUM_PAYMENT_WECHAT_MP_TYPE } from "./core.define";
import { MarketOrder } from "@/river-market/schema.order";

/** 微信小程序支付，远程记录 */
export type PaymentWeChatMp = ExtOwner &
  ExtIdTuple & {
    type: ENUM_PAYMENT;
    amount: INTEGER_PG;
    orderId: ExtUUidTuple["uuid32"];

    wxTradeId: PaymentResWeChatMp["transaction_id"];
    wxTradeType: ENUM_PAYMENT_WECHAT_MP_TYPE;
    wxTradeState: ENUM_PAYMENT_WECHAT_MP_STATE;
    wxTradeStateDesc: PaymentResWeChatMp["trade_state_desc"];
    wxTradeQRCode: VARCHAR255_PG;
  } & {
    /** 用户购买钻石 */
    justMarketOrder?: MarketOrder;
  };

/** 微信小程序，客户支付结果
 *  https://pay.weixin.qq.com/docs/merchant/apis/native-payment/query-by-out-trade-no.html
 */
export type PaymentResWeChatMp = {
  amount: {
    currency: "CNY";
    payer_currency: "CNY";
    payer_total: number;
    total: number;
  };
  appid: string;
  mchid: string;
  success_time: string;
  trade_state: ENUM_PAYMENT_WECHAT_MP_STATE;
  trade_state_desc: string;
  trade_type: ENUM_PAYMENT_WECHAT_MP_TYPE;
  transaction_id: string;
};
